package com.ytsky.hctechnologysys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ytsky.hctechnologysys.dao.InstitutionMapper;
import com.ytsky.hctechnologysys.entity.Employee;
import com.ytsky.hctechnologysys.entity.Institution;
import com.ytsky.hctechnologysys.service.InstitutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class InstitutionServiceImpl implements InstitutionService {
    @Autowired
    private InstitutionMapper institutionMapper;

    @Override
    public boolean append(Institution institution) {
        return institutionMapper.insert(institution)>0;
    }

    @Override
    public PageInfo<Institution> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<Institution> institution = institutionMapper.selectByKeyword(keyword);
        PageInfo<Institution>  pageInfo = new PageInfo<>(institution);
        return pageInfo;
    }


    @Override
    public Institution findById(int id) {
        return  institutionMapper.selectById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean modify(Institution institution) {
        return institutionMapper.updateById(institution) > 0;
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean remove(int id) {
        return institutionMapper.deleteByid(id)>0;
    }
}
